<template>
    <div class="mb-2 mt-1">
      <el-space wrap :size="10" class="">
        <el-input
          v-model="params.win_name"
          style="width: 150px"
          placeholder="用戶名稱"
        />
        <el-input
          v-model="params.fb_user_id"
          style="width: 150px"
          placeholder="用戶ID"
        />
        <el-button :icon="Search" plain @click="search">查詢</el-button>
      </el-space>
    </div>
    <el-table ref="multipleTableRef" :data="tableData" style="width: 100%">
      <el-table-column type="index" width="55" label="序號" />
      <el-table-column label="用戶名稱" align="center">
        <template #default="scope">
          <div class="flex flex-column align-center">
            <el-image
              style="width: 80px; height: 80px"
              :src="scope.row.win_avatar"
              fit="cover"
            />
            <div class="mt">{{ scope.row.win_name }}</div>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="fb_user_id" label="用戶ID" />
      <el-table-column prop="win_nums" label="得標次數" />
      <el-table-column prop="goods_nums" label="購物車購物數量" />
      <el-table-column label="購物車URL">
        <template #default="scope">
          <div class="text-ellipsis">{{ scope.row.cart_url }}</div>
          <div>
            <el-button
              link
              size="small"
              type="primary"
              @click="handleEdit(scope.$index, scope.row)"
              >複製</el-button
            >
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="200">
        <template #default="scope">
          <el-button
            link
            size="small"
            type="primary"
            @click="handleEdit(scope.$index, scope.row)"
            >購物車</el-button
          >
          <el-button
            link
            size="small"
            type="danger"
            @click="handleEdit(scope.$index, scope.row)"
            >私訊對話</el-button
          >
          <el-button
            link
            size="small"
            type="info"
            @click="handleDelete(scope.$index, scope.row)"
            >用戶同步</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="mt-2 flex justify-center">
      <el-pagination
        v-model:current-page="params.current_page"
        v-model:page-size="params.page_size"
        :page-sizes="[10, 20, 30, 40]"
        :small="false"
        :disabled="false"
        :background="true"
        layout="total, sizes, prev, pager, next"
        :total="Number(total)"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
</template>
<script lang="ts" setup>
import { ref, onMounted } from "vue";
import { Search, Goods } from "@element-plus/icons-vue";
import { $getAllCart } from "@api/live";
import { dayjs } from "element-plus";
let params = ref({
  current_page: 1,
  page_size: 10,
  fb_user_id: "",
  win_name: "",
});
const loading = ref(false);
const total = ref(0);
const tableData = ref([]);
onMounted(() => {
  getData();
});
const getData = async () => {
  loading.value = true;
  let res = await $getAllCart(params.value);
  loading.value = false;
  if (res.code == 0) {
    tableData.value = res.data.table;
    total.value = res.data.total;
  }
};
const handleSizeChange = (val: number) => {
  params.value.page_size = val;
  getData();
};
const handleCurrentChange = (val: number) => {
  params.value.current_page = val;
  getData();
  console.log(`current page: ${val}`);
};
const handleSelectionChange = (val: array) => {
  console.log(val);
  multipleSelection.value = val;
};
const disabledDateFun = (date) => {
  let now = dayjs().subtract(1, "day");
  if (date < now) return false;
  return true;
};
const search = () => {
  console.log(params.value);
  getData();
};
</script>

<style lang="scss" scoped></style>